package service

import (
	"ksd-social-api/modules/course/mapper"
	"ksd-social-api/modules/course/model/vo"
)

type CourseService struct{}

var courseMapper = mapper.CourseMapper{}

/**
 * @author feige
 * @date 2023-10-08
 * @desc 根据id查询课程信息的业务蹭
 */
func (service *CourseService) GetCourseByID(id uint64, userId uint64) (pvo *vo.CourseVo, err error) {
	// 1: 根据id查询数据层
	course, err := courseMapper.GetById(id)
	if err != nil {
		return nil, err
	}

	courseVo := vo.CourseVo{}
	// 2: 如果没有错误就必须把model数据导入vo数据中
	courseVo.ID = course.ID
	courseVo.Title = course.Title
	courseVo.Content = course.Content
	// 3: 查询当前登录的用户信息和课程id去查询用户课程收藏表
	//count1 := courseMapper.countUserCourseFav(id,userId)
	courseVo.FavFlag = 1
	//count2 := courseMapper.countUserCourseLike(id,userId)
	// 3: 查询当前登录的用户信息和课程id去查询用户课程点赞表
	courseVo.LikeFlag = 0

	return &courseVo, err
}
